import 'package:flutter/material.dart';
import '/utils/setting.dart';

class CustomTabBar extends StatefulWidget {
  final List tabs;
  final List<Widget> children;
  const CustomTabBar({
    super.key,
    required this.tabs,
    required this.children,
  });

  @override
  State<CustomTabBar> createState() => _CustomTabBarState();
}

class _CustomTabBarState extends State<CustomTabBar> with SingleTickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: widget.tabs.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        TabBar(
          indicatorColor: DefaultColor.success,
          labelColor: DefaultColor.success,
          controller: _tabController,
          tabs: widget.tabs.map((e) => Tab(text: e)).toList()
        ),
        Expanded(
          child: TabBarView(
            controller: _tabController,
            children: widget.children.map((cell) => cell).toList(),
          ),
        ),
      ],
    );
  }
}